<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
	
    <h:body>	
		<ui:composition template="/admin/template.xhtml">		    			
		<p:panel header="Články">	
			<h:panelGrid columns="2">
				<p:panel header="#{articleBean.categoryName}" style="min-height: 1129px;">   
				   <h:form id="articleForm">	
					    	<p:dataTable id="seaspmTable" var="article" value="#{articleBean.articleListVybor}" rowKey="#{article.id}" paginator="true" rows="15" paginatorAlwaysVisible="false" paginatorPosition="bottom" selection="#{articleBean.selectedArticle}" selectionMode="single" emptyMessage="Žádné články nenalazeny"  tableStyle="min-width:300px;">
						        <f:facet name="header">
									<h:outputText value="Seznam článků" />
						        </f:facet>
						        <p:column headerText="název">  
						            <h:outputText value="#{article.name}" />  
						        </p:column>
						        <c:if test="#{articleBean.category eq 'informace'}">
							        <p:column headerText="priorita">  
							            <h:outputText value="#{article.priority}" />  
							        </p:column>
						        </c:if>
						        <c:if test="#{articleBean.category eq 'clanky'}">
							        <p:column headerText="zobrazit">  
							            <h:outputText value="#{article.zobrazit}" />  
							        </p:column>
						        </c:if>
						        <f:facet name="footer">  
					            	<p:commandButton icon="ui-icon-pencil" value="upravit článek" update=":articleEditDialog" oncomplete="articleEditDialog.show()"/>
					                <p:commandButton icon="ui-icon-document" value="nový článek"  update=":articleForm" oncomplete="articleNewDialog.show()"/>     
					       			<p:commandButton value="Odstranit" actionListener="#{articleBean.deleteArticle}" update=":articleForm,:growl" />
					       		</f:facet>     
					  	    </p:dataTable>
					</h:form>
					
					
					
					<p:dialog id="articleNewDialog" header="Nový článek" widgetVar="articleNewDialog" resizable="false"  
					              width="700" showEffect="clip" hideEffect="fold" position="10,10">  
						      	 <h:form>   
						      	    <h:panelGrid columns="2" cellpadding="4">
						      	       <h:outputText value="Název Článku:" />  
						      	       <h:inputText id="newArticleName" value="#{articleBean.newArticle.name}" style="width:400px"/>
						      	       <h:outputText value="Autor Článku:" />  
						      	       <h:inputText value="#{articleBean.newArticle.author}" style="width:100px"/>
						      	       <h:outputText value="Text Článku:" />    						      
							           <p:editor id="editor1" value="#{articleBean.newArticle.content}" width="600"/>   	 
						        	   <c:if test="#{articleBean.category != 'informace'}">
							        	   <h:outputText value="Krátký popis:" />
									       <p:inputTextarea value="#{articleBean.newArticle.shortContent}" style="width:600px" maxheight="200" autoResize="false" />
									   </c:if>
									   <c:if test="#{articleBean.category eq 'informace'}">
									       <h:outputText value="priorita:" />
									       <h:inputText value="#{articleBean.newArticle.priority}" style="width:15px" />
								       </c:if>
								       <c:if test="#{articleBean.category eq 'clanky'}">
									       <h:outputText value="zobrazit:" />
									       <p:selectOneMenu value="#{articleBean.newArticle.zobrazit}" style="width: 80px" >  
										                <f:selectItem  itemLabel="vyberte" itemValue="" />
										                <f:selectItem  itemLabel="ano" itemValue="ano" />  
										                <f:selectItem  itemLabel="ne" itemValue="ne" /> 
				            			   </p:selectOneMenu>
								       </c:if>
								    </h:panelGrid> 
						        	<p:commandButton value="Vytvoř článek"  actionListener="#{articleBean.createArticleVybor}" update=":articleForm,:articleNewDialog,:growl" oncomplete="articleNewDialog.hide()"/> 
						        </h:form>	
					</p:dialog>
					
					<p:dialog id="articleEditDialog" header="Editovat článek" widgetVar="articleEditDialog" resizable="false"  
					              width="700" showEffect="clip" hideEffect="fold" position="10,10">  
						      	 <h:form>   
						      	    <h:panelGrid columns="2" cellpadding="4">
						      	       <h:outputText value="Jméno:" />    						      
							           <h:inputText value="#{articleBean.selectedArticle.name}" style="width:400px" required="true"/> 
							           <h:outputText value="Autor Článku:" />  
						      	       <h:inputText value="#{articleBean.selectedArticle.author}" style="width:100px"/>   
							           <h:outputText value="Text Článku:" />    						      
							           <p:editor id="editor2" value="#{articleBean.selectedArticle.content}" width="600" required="true"/>	 
							           <c:if test="#{articleBean.category != 'informace'}">
								           <h:outputText value="Krátký popis:" />
								           <p:inputTextarea value="#{articleBean.selectedArticle.shortContent}" style="width:600px" maxheight="200" autoResize="false" />
							           </c:if>
							           <c:if test="#{articleBean.category eq 'informace'}">
							        	   <h:outputText value="priorita:" />
									       <h:inputText value="#{articleBean.selectedArticle.priority}" style="width:15px" />
						        	   </c:if>
						        	   <c:if test="#{articleBean.category eq 'clanky'}">
									       <h:outputText value="zobrazit:" />
									       <p:selectOneMenu value="#{articleBean.selectedArticle.zobrazit}" style="width: 80px" >  
										                <f:selectItem  itemLabel="vyberte" itemValue="" />
										                <f:selectItem  itemLabel="ano" itemValue="ano" />  
										                <f:selectItem  itemLabel="ne" itemValue="ne" /> 
				            			   </p:selectOneMenu>
								       </c:if>
						        	</h:panelGrid> 
						        	<p:commandButton value="Ulož změny"  actionListener="#{articleBean.updateArticle}" update=":articleForm,:growl" oncomplete="articleEditDialog.hide()"/>  
						        </h:form>	
					 </p:dialog>
					
				</p:panel>
			</h:panelGrid>
		</p:panel>			
		</ui:composition>	
	</h:body>
</html>